﻿using System;
using System.Collections.Generic;

namespace TableTypes
{
    public class ReservedTableEntry
    {
        public ClassName ClassName = null;
        public ClassTime ClassTime  = null;
        public int ClassId = 0;
    }

    public class ReservedTable : List<ReservedTableEntry>
    {
        public static ReservedTable Fetch(WebLayer.LoginToken loginToken)
        {
            WebParser.WebPageCache pageCache = new WebParser.WebPageCache();
            pageCache.LoginToken = loginToken;

            return Fetch(pageCache);
        }
        public static ReservedTable Fetch(WebParser.WebPageCache pageCache)
        {
            WebParser.ReservationsWebPage webPage = pageCache.GetPage<WebParser.ReservationsWebPage>();

            ReservedTable reservedTable = new ReservedTable();
            foreach (WebParser.ReservedTableEntry webEntry in webPage.ReservedTableContent)
            {
                ReservedTableEntry memEntry = new ReservedTableEntry();

                memEntry.ClassName = ClassName.ParseClassName(webEntry.Class);
                memEntry.ClassTime = ClassTime.ParseReservedEntry(webEntry.Date);
                memEntry.ClassId = Int32.Parse(webEntry.Cancel);

                reservedTable.Add(memEntry);
            }

            return reservedTable;
        }
    }
}
